package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.QuerySellerProductTagsBean;
import com.ymatou.iapi.productmanager.parameter.SellerProductTagsDto;
import com.ymatou.iapi.productmanager.service.QuerySellerProductTagsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.utils.TestDataManager;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
*查询营销标签列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QuerySellerProductTags{
	private static QuerySellerProductTagsBean querysellerproducttagsBean;
	private static QuerySellerProductTagsCall querysellerproducttagsCall;
	private static IntergratedProductMapper intergratedProductMapper = SqlMapperFactory.getIntergratedProductMapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询营销标签列表");
	}

	@Before
	public void caseUp() {
		querysellerproducttagsBean=new QuerySellerProductTagsBean();
		querysellerproducttagsCall=new QuerySellerProductTagsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querysellerproducttagsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QuerySellerProductTags_001() {
		Logger.start(true,"查询营销标签列表成功");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
			querysellerproducttagsBean.setSellerId(sellerId);
			querysellerproducttagsBean.setCategoryId(cid);
			querysellerproducttagsBean.setThirdcategoryId(thirdcategoryid);
			querysellerproducttagsCall.setData(querysellerproducttagsBean);
			querysellerproducttagsCall.callService();			
			Logger.verifyEquals("200", querysellerproducttagsCall.getString("Code"), "验证code");
			querysellerproducttagsCall.getSellerProductTagsDto().forEach(x->{
				Map m=intergratedProductMapper.selectYmtSellerProductTagById(x.getId()).get(0);
				Logger.verifyEquals(x.getSellerId(), m.get("SellerId"), "验证sellerid");
				Logger.verifyEquals(x.getTag(), m.get("Tag"), "验证Tag");
				Logger.verifyEquals(x.getCategoryId(), m.get("CategoryId"), "验证CategoryId");
				Logger.verifyEquals(x.getThirdcategoryId(), m.get("ThirdcategoryId"), "验证ThirdcategoryId");
				Logger.verifyEquals(0, m.get("Status"), "验证Status");
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QuerySellerProductTags_002() {
		Logger.start(true,"不输入sellerid失败");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
//			querysellerproducttagsBean.setSellerId(sellerId);
			querysellerproducttagsBean.setCategoryId(cid);
			querysellerproducttagsBean.setThirdcategoryId(thirdcategoryid);
			querysellerproducttagsCall.setData(querysellerproducttagsBean);
			querysellerproducttagsCall.callService();			
			Logger.verifyEquals("400", querysellerproducttagsCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QuerySellerProductTags_003() {
		Logger.start(true,"不输入categoryId失败");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
			querysellerproducttagsBean.setSellerId(sellerId);
//			querysellerproducttagsBean.setCategoryId(cid);
			querysellerproducttagsBean.setThirdcategoryId(thirdcategoryid);
			querysellerproducttagsCall.setData(querysellerproducttagsBean);
			querysellerproducttagsCall.callService();			
			Logger.verifyEquals("400", querysellerproducttagsCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QuerySellerProductTags_004() {
		Logger.start(true,"不输入thirdcategoryId失败");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
			querysellerproducttagsBean.setSellerId(sellerId);
			querysellerproducttagsBean.setCategoryId(cid);
//			querysellerproducttagsBean.setThirdcategoryId(thirdcategoryid);
			querysellerproducttagsCall.setData(querysellerproducttagsBean);
			querysellerproducttagsCall.callService();			
			Logger.verifyEquals("400", querysellerproducttagsCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QuerySellerProductTags_005() {
		Logger.start(true,"已删除标签不会查出");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			querysellerproducttagsBean.setSellerId(sellerId);
			querysellerproducttagsBean.setCategoryId(cid);
			querysellerproducttagsBean.setThirdcategoryId(thirdcategoryid);
			querysellerproducttagsCall.setData(querysellerproducttagsBean);
			querysellerproducttagsCall.callService();			
			Logger.verifyEquals("200", querysellerproducttagsCall.getString("Code"), "验证code");
			Logger.verifyEquals(0, querysellerproducttagsCall.getSellerProductTagsDto().size(), "删除的不会查出");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QuerySellerProductTags_006() {
		Logger.start(true,"一级固定标签可以查出");
		try {
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			querysellerproducttagsBean.setSellerId(sellerId);
			querysellerproducttagsBean.setCategoryId(1086);
			querysellerproducttagsBean.setThirdcategoryId(thirdcategoryid);
			querysellerproducttagsCall.setData(querysellerproducttagsBean);
			querysellerproducttagsCall.callService();			
			Logger.verifyEquals("200", querysellerproducttagsCall.getString("Code"), "验证code");
			querysellerproducttagsCall.getSellerProductTagsDto().forEach(x->{
				Map m=intergratedProductMapper.selectYmtSellerProductTagById(x.getId()).get(0);
				Logger.verifyEquals(x.getSellerId(), m.get("SellerId"), "验证sellerid");
				Logger.verifyEquals(x.getTag(), m.get("Tag"), "验证Tag");
				Logger.verifyEquals(x.getCategoryId(), m.get("CategoryId"), "验证CategoryId");
				Logger.verifyEquals(x.getThirdcategoryId(), m.get("ThirdcategoryId"), "验证ThirdcategoryId");
				Logger.verifyEquals(0, m.get("Status"), "验证Status");
			});	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QuerySellerProductTags_007() {
		Logger.start(true,"查询顺序-固定标签在前,最近使用的标签倒叙");
		try {
			IntergratedProductMapper intergratedProductMapper = SqlMapperFactory.getIntergratedProductMapper();
			Integer sellerId=1;
			Integer cid=1001;
			Integer thirdcategoryid=1003;
			String tag="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag);
			Thread.sleep(1000);
			String tag2="T"+TestDataManager.getRandomNum(4);
			ProductManagerCallServiceV3.DeleteAllSellerPorductTags(sellerId, thirdcategoryid);
			int tagId2=ProductManagerCallServiceV3.AddSellerPorductTags(sellerId, cid, thirdcategoryid, tag2);
			
			querysellerproducttagsBean.setSellerId(sellerId);
			querysellerproducttagsBean.setCategoryId(cid);
			querysellerproducttagsBean.setThirdcategoryId(thirdcategoryid);
			querysellerproducttagsCall.setData(querysellerproducttagsBean);
			querysellerproducttagsCall.callService();			
			Logger.verifyEquals("200", querysellerproducttagsCall.getString("Code"), "验证code");
			List<SellerProductTagsDto> list = querysellerproducttagsCall.getSellerProductTagsDto();
			 List<Map> db1 = intergratedProductMapper.selectYmtSellerProductTagByCategoryId(0, cid);
			 Logger.debug("db1:"+db1);
			 List<Map> db2 = intergratedProductMapper.selectYmtSellerProductTag(sellerId, thirdcategoryid);
			 Logger.debug("db2:"+db2);
			 List<Map> db3=new ArrayList<Map>();
			 db3.addAll(db1);
			 db3.addAll(db2);
			 Logger.debug("db3:"+db3);
			 Logger.verifyEquals(db3.size(), list.size(), "验证size");
			 int allsize=list.size();
			 for (int j = 0; j < allsize; j++) {
				Logger.verifyEquals(db3.get(j).get("Id").toString(), list.get(j).getId().toString(),"验证顺序");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}